/*
 * Copyright (C) 2012 rothens
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package rpg.ui.components;

import rpg.RPG;
import rpg.gfx.Bitmap;
import rpg.util.BoundingBox;

/**
 *
 * @author rothens
 */
public abstract class Component extends Bitmap {

    protected Integer x;
    protected Integer y;
    protected BoundingBox bb;
    protected ComponentState state = ComponentState.INACTIVE;
    protected boolean focusable = true;
    protected ISubcomponentHolder parent = null;

    public Component(int width, int height, Integer x, Integer y) {
        super(width, height);
        this.y = (y == null) ? RPG.WINDOW_HEIGHT / 2 - height / 2 : y;
        this.x = (x == null) ? RPG.WINDOW_WIDTH / 2 - width / 2 : x;
        bb = new BoundingBox(this.x, this.y, width, height);
    }
    
    public int getX() {
        return x;
    }

    public void setX(Integer x) {
        this.x = (x == null) ? RPG.WINDOW_WIDTH / 2 - width / 2 : x;
        bb.setX(this.x);
    }

    public int getY() {
        return y;
    }

    public void setY(Integer y) {
        this.y = (y == null) ? RPG.WINDOW_HEIGHT / 2 - height / 2 : y;
        bb.setY(this.y);
    }

    public ComponentState getState() {
        return state;
    }

    public void setState(ComponentState state) {
        if(this.state != state){
            this.state = state;
            redraw();
        }
        
    }

    public boolean isMouseOver(int x, int y) {
        return bb.isMouseOver(x, y);
    }

    public boolean isFocusable() {
        return focusable;
    }

    public void setFocusable(boolean focusable) {
        this.focusable = focusable;
    }

    public void action() {
    }

    public void redraw(){
        /*if(parent != null){
            ((Component)parent).redraw();
        }*/
    }

    public ISubcomponentHolder getParent() {
        return parent;
    }

    public void setParent(ISubcomponentHolder parent) {
        this.parent = parent;
    }
}
